#include "lolevel.h"
#include "platform.h"
#include "core.h"

static long *nrflag = (long*)0xE618;

#include "../../../generic/capt_seq.c"

void __attribute__((naked,noinline)) capt_seq_task() {
 asm volatile (
                "STMFD   SP!, {R3-R9,LR}\n"
                "LDR     R6, =0x1E454\n"
                "LDR     R5, =0x583C\n"
                "MOV     R9, #1\n"
                "MOV     R7, #0\n"
"loc_FF861224:\n"
                "LDR     R0, [R5,#0x14]\n"
                "MOV     R2, #0\n"
                "MOV     R1, SP\n"
                "BL      sub_FF829FB0\n"
                "TST     R0, #1\n"
                "BEQ     loc_FF861250\n"
                "LDR     R1, =0x43F\n"
                "LDR     R0, =0xFF860C6C\n"
                "BL      sub_FF81BFC8\n"
                "BL      sub_FF81BD80\n"
                "LDMFD   SP!, {R3-R9,PC}\n"
"loc_FF861250:\n"
                "LDR     R0, [SP]\n"
                "LDR     R1, [R0]\n"
                "CMP     R1, #0x1C\n"
                "ADDLS   PC, PC, R1,LSL#2\n"
                "B       loc_FF8614AC\n"
"loc_FF861264:\n"
                "B       loc_FF8612D8\n"
"loc_FF861268:\n"
                "B       loc_FF861348\n"
"loc_FF86126C:\n"
                "B       loc_FF861350\n"
"loc_FF861270:\n"
                "B       loc_FF861368\n"
"loc_FF861274:\n"
                "B       loc_FF86135C\n"
"loc_FF861278:\n"
                "B       loc_FF861370\n"
"loc_FF86127C:\n"
                "B       loc_FF861378\n"
"loc_FF861280:\n"
                "B       loc_FF861380\n"
"loc_FF861284:\n"
                "B       loc_FF8613D8\n"
"loc_FF861288:\n"
                "B       loc_FF8613E4\n"
"loc_FF86128C:\n"
                "B       loc_FF8613EC\n"
"loc_FF861290:\n"
                "B       loc_FF8613F4\n"
"loc_FF861294:\n"
                "B       loc_FF8613FC\n"
"loc_FF861298:\n"
                "B       loc_FF861404\n"
"loc_FF86129C:\n"
                "B       loc_FF86140C\n"
"loc_FF8612A0:\n"
                "B       loc_FF861414\n"
"loc_FF8612A4:\n"
                "B       loc_FF86141C\n"
"loc_FF8612A8:\n"
                "B       loc_FF861424\n"
"loc_FF8612AC:\n"
                "B       loc_FF86142C\n"
"loc_FF8612B0:\n"
                "B       loc_FF861434\n"
"loc_FF8612B4:\n"
                "B       loc_FF86143C\n"
"loc_FF8612B8:\n"
                "B       loc_FF861444\n"
"loc_FF8612BC:\n"
                "B       loc_FF861450\n"
"loc_FF8612C0:\n"
                "B       loc_FF86145C\n"
"loc_FF8612C4:\n"
                "B       loc_FF861464\n"
"loc_FF8612C8:\n"
                "B       loc_FF861494\n"
"loc_FF8612CC:\n"
                "B       loc_FF86149C\n"
"loc_FF8612D0:\n"
                "B       loc_FF8614A4\n"
"loc_FF8612D4:\n"
                "B       loc_FF8614B8\n"
"loc_FF8612D8:\n"
                "BL      sub_FF942490\n"
                "BL      shooting_expo_param_override\n"  // +
                "BL      sub_FF85F050\n"
                "LDR     R0, [R6,#0x24]\n"
                "CMP     R0, #0\n"
                "BEQ     loc_FF8614B8\n"
                "BL      sub_FF860938\n"
                "MOV     R4, R0\n"
                "LDR     R0, [R6,#0x24]\n"
                "CMP     R0, #0\n"
                "BEQ     loc_FF861320\n"
                "MOV     R0, #0xC\n"
                "BL      sub_FF86499C\n"
                "TST     R0, #1\n"
                "STRNE   R9, [R5,#4]\n"
                "LDRNE   R0, [R4,#8]\n"
                "ORRNE   R0, R0, #0x40000000\n"
                "STRNE   R0, [R4,#8]\n"
                "BNE     loc_FF8614B8\n"
"loc_FF861320:\n"
                "MOV     R0, R4\n"
                "BL      sub_FF943F2C\n"
                "BL      sub_FF957C54\n"
                "BL      sub_FF86F8F8\n"
                "STR     R0, [R4,#0x14]\n"
                "MOV     R0, R4\n"
                "BL      sub_FF944484_my\n"             //-------->
                "BL      capt_seq_hook_raw_here\n"      // +
                "TST     R0, #1\n"
                "STRNE   R9, [R5,#4]\n"
                "B       loc_FF8614B8\n"
"loc_FF861348:\n"
                "BL      sub_FF860CEC_my\n"            //-------->
                "B       loc_FF861360\n"
"loc_FF861350:\n"
                "MOV     R0, #1\n"
                "BL      sub_FF942690\n"
                "B       loc_FF8614B8\n"
"loc_FF86135C:\n"
                "BL      sub_FF94218C\n"
"loc_FF861360:\n"
                "STR     R7, [R6,#0x24]\n"
                "B       loc_FF8614B8\n"
"loc_FF861368:\n"
                "BL      sub_FF942424\n"
                "B       loc_FF861360\n"
"loc_FF861370:\n"
                "BL      sub_FF94242C\n"
                "B       loc_FF8614B8\n"
"loc_FF861378:\n"
                "BL      sub_FF942580\n"
                "B       loc_FF8613DC\n"
"loc_FF861380:\n"
                "LDR     R4, [R0,#0xC]\n"
                "BL      sub_FF942434\n"
                "MOV     R0, R4\n"
                "BL      sub_FF942FC4\n"
                "TST     R0, #1\n"
                "MOV     R8, R0\n"
                "BNE     loc_FF8613C0\n"
                "BL      sub_FF86F8F8\n"
                "STR     R0, [R4,#0x14]\n"
                "MOV     R0, R4\n"
                "BL      sub_FF94439C\n"
                "MOV     R0, R4\n"
                "BL      sub_FF944990\n"
                "MOV     R8, R0\n"
                "LDR     R0, [R4,#0x14]\n"
                "BL      sub_FF86FB0C\n"
"loc_FF8613C0:\n"
                "BL      sub_FF942424\n"
                "MOV     R2, R4\n"
                "MOV     R1, #8\n"
                "MOV     R0, R8\n"
                "BL      sub_FF85F620\n"
                "B       loc_FF8614B8\n"
"loc_FF8613D8:\n"
                "BL      sub_FF94260C\n"
"loc_FF8613DC:\n"
                "BL      sub_FF85F050\n"
                "B       loc_FF8614B8\n"
"loc_FF8613E4:\n"
                "BL      sub_FF942424\n"
                "B       loc_FF8614B8\n"
"loc_FF8613EC:\n"
                "BL      sub_FF94323C\n"
                "B       loc_FF8614B8\n"
"loc_FF8613F4:\n"
                "BL      sub_FF943438\n"
                "B       loc_FF8614B8\n"
"loc_FF8613FC:\n"
                "BL      sub_FF9434CC\n"
                "B       loc_FF8614B8\n"
"loc_FF861404:\n"
                "BL      sub_FF9435F4\n"
                "B       loc_FF8614B8\n"
"loc_FF86140C:\n"
                "BL      sub_FF9436A8\n"
                "B       loc_FF8614B8\n"
"loc_FF861414:\n"
                "BL      sub_FF943A7C\n"
                "B       loc_FF8614B8\n"
"loc_FF86141C:\n"
                "BL      sub_FF943ACC\n"
                "B       loc_FF8614B8\n"
"loc_FF861424:\n"
                "MOV     R0, #0\n"
                "B       loc_FF861448\n"
"loc_FF86142C:\n"
                "BL      sub_FF943C70\n"
                "B       loc_FF8614B8\n"
"loc_FF861434:\n"
                "BL      sub_FF943D04\n"
                "B       loc_FF8614B8\n"
"loc_FF86143C:\n"
                "BL      sub_FF943DC4\n"
                "B       loc_FF8614B8\n"
"loc_FF861444:\n"
                "MOV     R0, #1\n"
"loc_FF861448:\n"
                "BL      sub_FF943B30\n"
                "B       loc_FF8614B8\n"
"loc_FF861450:\n"
                "BL      sub_FF94282C\n"
                "BL      sub_FF8615D0\n"
                "B       loc_FF8614B8\n"
"loc_FF86145C:\n"
                "BL      sub_FF943920\n"
                "B       loc_FF8614B8\n"
"loc_FF861464:\n"
                "MOV     R2, #2\n"
                "ADD     R1, R6, #0x58\n"
                "MOV     R0, #0x6F\n"
                "BL      sub_FF86F768\n"
                "TST     R0, #1\n"
                "LDRNE   R1, =0x502\n"
                "LDRNE   R0, =0xFF860C6C\n"
                "BLNE    sub_FF81BFC8\n"
                "LDRH    R0, [R6,#0x58]\n"
                "CMP     R0, #1\n"
                "BLEQ    sub_FF943914\n"
                "B       loc_FF8614B8\n"
"loc_FF861494:\n"
                "BL      sub_FF9439E4\n"
                "B       loc_FF8614B8\n"
"loc_FF86149C:\n"
                "BL      sub_FF860BD0\n"
                "B       loc_FF8614B8\n"
"loc_FF8614A4:\n"
                "BL      sub_FF826210\n"
                "B       loc_FF8614B8\n"
"loc_FF8614AC:\n"
                "LDR     R1, =0x523\n"
                "LDR     R0, =0xFF860C6C\n"
                "BL      sub_FF81BFC8\n"
"loc_FF8614B8:\n"
                "LDR     R0, [SP]\n"
                "LDR     R1, [R0,#4]\n"
                "LDR     R0, [R5,#0x10]\n"
                "BL      sub_FF829D2C\n"
                "LDR     R4, [SP]\n"
                "LDR     R0, [R4,#8]\n"
                "CMP     R0, #0\n"
                "LDREQ   R0, =0xFF860C6C\n"
                "MOVEQ   R1, #0xFC\n"
                "BLEQ    sub_FF81BFC8\n"
                "STR     R7, [R4,#8]\n"
                "B       loc_FF861224\n"
 );
} 


//ok
void __attribute__((naked,noinline)) sub_FF860CEC_my(){ // 
 asm volatile(
                "STMFD   SP!, {R3-R9,LR}\n"
                "LDR     R4, [R0,#0xC]\n"
                "LDR     R5, =0x1E454\n"
                "LDR     R0, [R4,#8]\n"
                "LDR     R6, =0x820A\n"
                "ORR     R0, R0, #1\n"
                "STR     R0, [R4,#8]\n"
                "LDRH    R0, [R5]\n"
                "LDR     R8, =0x583C\n"
                "MOV     R7, #0\n"
                "CMP     R0, R6\n"
                "BEQ     loc_FF860D90\n"
                "LDRH    R0, [R5,#0x86]\n"
                "CMP     R0, #3\n"
                "BEQ     loc_FF860DF0\n"
                "LDR     R0, [R4,#0xC]\n"
                "CMP     R0, #1\n"
                "BLS     loc_FF860D9C\n"
                "LDRH    R0, [R5,#0x84]\n"
                "CMP     R0, #0\n"
                "BNE     loc_FF860DF0\n"
                "LDRH    R0, [R5,#0x80]\n"
                "CMP     R0, #2\n"
                "BNE     loc_FF860DA8\n"
                "BL      sub_FF9428E0\n"
                "LDRH    R0, [R5]\n"
                "CMP     R0, R6\n"
                "BEQ     loc_FF860D90\n"
                "LDRH    R0, [R5,#0x86]\n"
                "CMP     R0, #3\n"
                "BEQ     loc_FF860DF0\n"
                "LDR     R0, [R4,#0xC]\n"
                "CMP     R0, #1\n"
                "BLS     loc_FF860D9C\n"
                "LDRH    R0, [R5,#0x84]\n"
                "CMP     R0, #0\n"
                "BNE     loc_FF860DF0\n"
                "LDRH    R0, [R5,#0x80]\n"
                "CMP     R0, #2\n"
                "BEQ     loc_FF860DD4\n"
                "B       loc_FF860DA8\n"
"loc_FF860D90:\n"
                "LDRH    R0, [R5,#0x86]\n"
                "CMP     R0, #3\n"
                "BEQ     loc_FF860DF0\n"
"loc_FF860D9C:\n"
                "LDRH    R0, [R5,#0x84]\n"
                "CMP     R0, #0\n"
                "BNE     loc_FF860DF0\n"
"loc_FF860DA8:\n"
                "LDRH    R0, [R5,#0x80]\n"
                "CMP     R0, #1\n"
                "BNE     loc_FF860DF0\n"
                "LDRH    R0, [R5]\n"
                "CMP     R0, R6\n"
                "LDRNE   R0, [R4,#0xC]\n"
                "CMPNE   R0, #1\n"
                "BLS     loc_FF860DF0\n"
                "LDR     R0, [R4,#0x10]\n"
                "CMP     R0, #1\n"
                "BNE     loc_FF860DF0\n"
"loc_FF860DD4:\n"
                "LDR     R3, =0x20D\n"
                "LDR     R2, =0xEA60\n"
                "STR     R3, [SP]\n"
                "LDR     R0, [R8,#0x10]\n"
                "LDR     R3, =0xFF860C6C\n"
                "MOV     R1, #0x40000000\n"
                "BL      sub_FF864D24\n"
"loc_FF860DF0:\n"
                "BL      sub_FF860BD0\n"
                "LDR     R0, [R5,#0x24]\n"
                "CMP     R0, #0\n"
                "MOVEQ   R0, #2\n"
                "BLEQ    sub_FF85B94C\n"
                "BL      sub_FF942434\n"
                "LDR     R0, [R5,#0x24]\n"
                "CMP     R0, #0\n"
                "BNE     loc_FF860E60\n"
                "MOV     R0, R4\n"
                "BL      sub_FF943F2C\n"
                "MOV     R0, R4\n"
                "BL      sub_FF942B9C\n"
                "TST     R0, #1\n"
                "MOVNE   R2, R4\n"
                "LDMNEFD SP!, {R3-R9,LR}\n"
                "MOVNE   R1, #1\n"
                "BNE     sub_FF85F620\n"
                "BL      sub_FF957C54\n"
                "BL      sub_FF86F8F8\n"
                "STR     R0, [R4,#0x14]\n"
                "MOV     R0, R4\n"
                "BL      sub_FF94439C\n"
                "BL      sub_FF944EDC\n"
                "MOV     R0, R4\n"
                "BL      sub_FF944484_my\n"         //------------->
                "MOV     R7, R0\n"
                "BL      capt_seq_hook_raw_here\n"  // +
                "B       loc_FF860E6C\n"
"loc_FF860E60:\n"
                "LDR     R0, [R8,#4]\n"
                "CMP     R0, #0\n"
                "MOVNE   R7, #0x1D\n"
"loc_FF860E6C:\n"
                "MOV     R2, R4\n"
                "MOV     R1, #1\n"
                "MOV     R0, R7\n"
                "BL      sub_FF85F620\n"
                "BL      sub_FF944930\n"
                "CMP     R0, #0\n"
                "LDRNE   R0, [R4,#8]\n"
                "ORRNE   R0, R0, #0x2000\n"
                "STRNE   R0, [R4,#8]\n"
                "LDRH    R0, [R5,#0x86]\n"
                "CMP     R0, #3\n"
                "BEQ     loc_FF860EB8\n"
                "LDRH    R0, [R5,#0x84]\n"
                "CMP     R0, #0\n"
                "LDREQH  R0, [R5,#0x80]\n"
                "CMPEQ   R0, #2\n"
                "MOVEQ   R0, R4\n"
                "LDMEQFD SP!, {R3-R9,LR}\n"
                "BEQ     sub_FF942934\n"
"loc_FF860EB8:\n"
                "LDMFD   SP!, {R3-R9,PC}\n"
 );
}



void __attribute__((naked,noinline)) sub_FF944484_my(){ // 
 asm volatile(
                 "STMFD   SP!, {R0-R10,LR}\n"
                 "MOV     R6, #0\n"
                 "MOV     R4, R0\n"
                 "BL      sub_FF945048\n"
                 "MVN     R1, #0\n"
                 "BL      sub_FF829D60\n"
                 "MOV     R2, #4\n"
                 "ADD     R1, SP, #8\n"
                 "MOV     R0, #0x8A\n"
                 "BL      sub_FF86F768\n"
                 "TST     R0, #1\n"
                 "LDRNE   R1, =0x20A\n"
                 "LDRNE   R0, =0xFF94468C\n"
                 "BLNE    sub_FF81BFC8\n"
                 "LDR     R8, =0x1E508\n"
                 "LDR     R5, =0x1E454\n"
                 "LDRSH   R1, [R8,#0xE]\n"
                 "LDR     R0, [R5,#0x7C]\n"
         //      "BL      nullsub_48\n"
                 "BL      sub_FF84BE78\n"
                 "LDR     R2, =0xE61C\n"
                 "ADD     R3, R4, #0x8C\n"
                 "STRH    R0, [R4,#0x88]\n"
                 "STRD    R2, [SP]\n"
                 "MOV     R1, R0\n"
                 "LDRH    R0, [R5,#0x54]\n"
                 "LDRSH   R2, [R8,#0xC]\n"
                 "LDR     R3, =0xE618\n"
                 "BL      sub_FF94553C\n"
                 "BL      wait_until_remote_button_is_released\n"  // +
                 "BL      capt_seq_hook_set_nr\n"                  // +              
                 "B       sub_FF9444F8\n"
 );
}
